// src/models/User.ts
import { DataTypes, Model, Optional } from "sequelize";
import sequelize from "../config/db";

// 定义用户模型接口
interface CtegoriesAttributes {
  id: number;
  name: string;
  description: string;
  status: number;
}

interface UserCreationAttributes extends Optional<CtegoriesAttributes, "id"> {}

class Ctegories
  extends Model<CtegoriesAttributes, UserCreationAttributes>
  implements CtegoriesAttributes
{
  public id!: number;
  public name!: string;
  public description!: string;
  public status!: number;
}

/**
 *
 * @
 *
 */
Ctegories.init(
  {
    id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true,
    },
    name: {
      type: DataTypes.STRING(50),
      allowNull: false,
      validate: {
        notEmpty: true, // 不允许为空字符串
      },
    },
    description: {
      type: DataTypes.TEXT,
      allowNull: false,
    },
    status: {
      type: DataTypes.TINYINT(),
      defaultValue: 1, // 默认启用
    },
  },
  {
    tableName: "categories",
    sequelize, // sequelize 实例
    timestamps: true,
  }
);

export default Ctegories;
